define([], function () {
    var app = angular.module('App');
    app.controller('statusCtrl', ['$scope', 'curPrj', 'viewbag', function ($scope, curPrj, viewbag) {
        $scope.curType = viewbag.curType;
        $scope.prj = viewbag.curPrj;
        $scope.totalStatusCount = curPrj.statusGroup.reduce(function (pre, cur) {
            return pre + cur.subItems.length;
        }, 0);
        $scope.curStatus = null;
        /** 设置缺省的当前工况 */
        function setDefaultCurStatus() {
            var tempStatus = null;
            var id = "";
            //如果之前访问过,就给出上次访问的工况
            for (var i = curPrj.statusGroup.length - 1; i >= 0; i--) {
                curPrj.statusGroup[i].active = false;
                for (var j = curPrj.statusGroup[i].subItems.length - 1; j >= 0; j--) {
                    if (curPrj.statusGroup[i].subItems[j].imagesUrl.length > 0 && tempStatus === null) {
                        tempStatus = curPrj.statusGroup[i].subItems[j];
                        id = 'status' + i;
                    }
                    if (curPrj.statusGroup[i].subItems[j].active) {
                        $scope.curStatus = curPrj.statusGroup[i].subItems[j];
                        $scope.curMainStatus = curPrj.statusGroup[i];
                        id = 'status' + i;
                        setTimeout(function () {
                            $('#status' + i).collapse('show');
                        }, 200);
                        return;
                    }
                }
            }
            //否则就默认加载最近有图片的一期工况
            if (tempStatus) {
                $scope.curStatus = tempStatus;
                $scope.curStatus.active = true;
                setTimeout(function () {
                    $('#' + id).collapse('show');
                }, 200);
                toastr.success('已为你展示最近有照片一期的工况.', '最新照片', { timeOut: 5000, "positionClass": "toast-bottom-right", "closeButton": true });
            } else {
                toastr.info('当前项目还未上传任何工况照片', '没有照片', { timeOut: 5000, "positionClass": "toast-bottom-right", "closeButton": true });
            }
        }
        setDefaultCurStatus();
        /** 设置当前的工况 */
        $scope.setCurStatus = function (status) {
            if (!status.imagesUrl.length) {
                toastr.warning('当前工况没有照片.', '无照片', { timeOut: 5000, "positionClass": "toast-bottom-right", "closeButton": true });
                return;
            }
            if ($scope.curStatus) $scope.curStatus.active = false;
            $scope.curStatus = status;
            $scope.curStatus.active = true;
            $('.full-height-content').animate({
                scrollTop: 0
            });
        };

        var a = []

    }]);
});